package com.libinshen.wxpay.common.exception;

import com.libinshen.wxpay.common.enums.BaseResponseCodeEnum;
import lombok.Data;

/**
 * @Author wangzhibo
 * @Date 2020/6/13 下午4:36
 **/
@Data
public class BaseException extends RuntimeException {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 结果信息
     */
    private String msg;

    /**
     * 数据
     */
    private Object data;

    public BaseException() {
    }

    public BaseException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseException(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static BaseException success(Object data) {
        return new BaseException(BaseResponseCodeEnum.SUCCESS_CODE.getCode(), "ok", data);
    }

    public static BaseException fail(Integer code, String message) {
        return new BaseException(code, message, null);
    }
}
